/**
 * 2018年12月15日下午2:47:17
 * @author 谢进财
 */
package com.baihang.project.ds.HandlerInterceptor;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import com.baihang.framework.kit.database.RedisKit;
import com.baihang.project.ds.common.CommonDao;
import com.baihang.project.ds.config.SystemConfig;

import redis.clients.jedis.Jedis;

/**
 *  拦截器
 *
 */
public class DsInterceptor implements HandlerInterceptor {

    private final static Logger logger = LoggerFactory.getLogger(DsInterceptor.class);
    private Jedis jedis = RedisKit.getJedis();
    @Autowired
    private CommonDao dao;
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.err.println("拦截前1");
		logger.info("拦截前");
		//String state = dao.queryForString("select Value from sys_config where Name='State'");
		String state = jedis.hmget("systemConfig","State").get(0);
		if("0".equals(state)) {
			request.getRequestDispatcher("/finish").forward(request, response);
		}
        return true;
		//return HandlerInterceptor.super.preHandle(request, response, handler);
	}
	
	private boolean isAjax(ServletRequest request){
        String header = ((HttpServletRequest) request).getHeader("X-Requested-With");
        if("XMLHttpRequest".equalsIgnoreCase(header)){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}
